/*函数保证输入框为金额格式
**error错误信息显示
*/
function mustDigit(error){
	if(event.keyCode<48||event.keyCode>57){
		event.returnValue=false;
	}
	if(event.keyCode==46){
		event.returnValue=true;
	}
}
function mustInt(){
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.returnValue = false;
	}
}
//去空格函数 
		
function Trim(str){ 
	return LTrim(RTrim(str)); 
} 
function LTrim(str){ 
	var i; 
	for(i=0;i<str.length;i++){ 
		if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
	} 
	str=str.substring(i,str.length); 
	return str; 
} 
		
function RTrim(str){ 
	var i; 
	for(i=str.length-1;i>=0;i--){ 
	 if(str.charAt(i)!=" "&&str.charAt(i)!=" ")
	 	break; 
	} 
	str=str.substring(0,i+1); 
	return str; 
} 
function PreviewImg(imgFile){
    //新的预览代码，支持 IE6、IE7。
    var newPreview = document.getElementById("newPreview");
    newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
    if(imgFile.value)
 			newPreview.style.height = "125px";
 			newPreview.style.width = "100px";
	if(newPreview.innerHTML.length > 0 ){
		newPreview.innerHTML = "";
	}				
}
function validateStringNull(title, value, ERROR){
	var value = getElementByIdValue(value);
	if(value == null || Trim(value) == ""){
	   getElementById("ERROR").innerHTML = title + "不能为空";
	   return false;
	}
	getElementById("ERROR").innerHTML = "";
	return true;
}
function validateAmountError(title, value, ERROR){
	if(value == null || value == ""){
	   return true;
	}
	if(!((/^([-]|[0-9])+(\.[0-9]{1,2})?$/).test(value))) {
	   getElementById("ERROR").innerHTML = title + "必须为金额格式";
	   return false;
	}
	return true;
}
function validateCardNoError(id) {
	if(!validateStringNull("身份证号码", id)) {
		return false;
	}
	var code = document.getElementById(id).value;
	if (code.length > 0 && !(/^\d{18}|\d{17}[xX]{1}|\d{15}$/).test(code)){
		throwError("请正确输入身份证号码!");
		return false;
	}
	return true;
}

function getElementByIdValue(id) {
	return getElementById(id).value;
}
function setElementByIdValue(id, value) {
	getElementById(id).value = value;
}
function getElementById(id) {
	var obj = document.getElementById(id);
	if(obj == null) {
		alert("id:"+id+"未定义");
		return;
	}
	return obj;
}
function getElementsByName(name) {
	return document.getElementsByName(name);
}
function displayNone(id) {
	getElementById(id).style.display = "none";
}
function displayBlock(id) {
	getElementById(id).style.display = "block";
}
function getRadioCheckedValue(name) {
	var obj = getElementsByName(name);
	for (var i = 0; i < obj.length; i++) {
	    if (obj[i].checked) {
	    	return obj[i].value;
	    }
	}
}
function getCheckboxCheckedString(name) {
	var obj = getElementsByName(name);
	var str = "";
	for (var i = 0; i < obj.length; i++) {
	    if (obj[i].checked) {
	    	str += (obj[i].value + ",");
	    }
	}
	return str;
}
function setCheckboxCheckedString(name, value) {
	if (value == null) {
		return;
	}
	var temp = value.split(",");
	var obj = getElementsByName(name);
	for (var i = 0; i < obj.length; i++) {
		for (var j = 0; j < temp.length; j++) {
		    if (obj[i].value == temp[j]) {
		    	obj[i].checked = true;
		    }
		}
	}
}
function getRadioCheckedString(name) {
	var obj = getElementsByName(name);
	var str = "";
	for (var i = 0; i < obj.length; i++) {
	    if (obj[i].checked) {
	    	str = (obj[i].value);
	    	break;
	    }
	}
	return str;
}
function openWindow(action) {
	return window.showModalDialog(action ,window, "scroll:no;dialogHeight=420px;dialogWidth=420px;");
}
function throwError(ERRORMessage) {
	document.getElementById("ERROR").innerHTML = ERRORMessage;
}
function chooseUser(url, id, name) {

	var names ="";
    var ids ="";
	var item = window.showModalDialog(url + "?time="+new Date().getTime(),window,"scroll:no;dialogHeight=420px;dialogWidth=420px;");
    if(item != null){
	    for(var i=0;i<item.length;i++) {
		    names += item[i][0]+",";
		    ids += item[i][1]+",";
	    }
	   	document.getElementById(id).value = ids;
	   	document.getElementById(name).value = names;
	}
}

function deleteChoose(id, name){
	if (id != null) {
    	document.getElementById(id).value = "";
    }
    if (name != null) {
    	document.getElementById(name).value = "";
    }
}

function choose(url, id, name, id2, name2) {

	var names ="";
    var ids ="";
	var item = window.showModalDialog(url + "?time="+new Date().getTime(),window,"scroll:no;dialogHeight=420px;dialogWidth=420px;");
    if(item != null){
	    if (id != null) {
	    	document.getElementById(id).value = item[0];
	    	if (document.getElementById(id2) != null) {
	    		document.getElementById(id2).value = item[0];
	    	}
	    }
	    if (name != null) {
	    	document.getElementById(name).value = item[1];
	    	if (document.getElementById(name2) != null) {
	    		document.getElementById(name2).value = item[1];
	    	}
	    }
	}
}
function deleteChoose(id, name, id2, name2){
	if (id != null) {
    	document.getElementById(id).value = "";
    	if (document.getElementById(id2) != null) {
    		document.getElementById(id2).value = "";
    	}
    }
    if (name != null) {
    	document.getElementById(name).value = "";
    	if (document.getElementById(name2) != null) {
    		document.getElementById(name2).value = "";
    	}
    }
}


function submit(form, obj) {
	obj.disabled = true;
	form.submit();
}
/*
 *	阻止网页上的右键操作
 *
 */
function Click(){
 	window.event.returnValue=false;
}
//document.oncontextmenu=Click;//阻止网页右键的脚本
function post2Server(url, data, callback) {
	$.post(url, data, function(u) {
		if (typeof(u) =='string' && u.indexOf('!DOCTYPE html') != -1) {
			window.document.open();
			window.document.write(u);
			//window.document.close();
		} else {
			if (jQuery.isFunction(callback)) {
				callback(u);
			} else {
				alert(u);
			}
		}
	});
}

